package com.online.teaching.module.admin.blog.controller;

import com.github.pagehelper.PageInfo;
import com.online.teaching.module.admin.blog.domain.vo.GetBlogListVO;
import com.online.teaching.module.admin.blog.domain.vo.GetCommentListVO;
import com.online.teaching.module.admin.blog.service.AdminBlogService;
import com.online.teaching.module.common.blog.domain.vo.BlogGetVO;
import com.online.teaching.utils.Result;
import com.online.teaching.utils.StatusCode;
import com.online.teaching.utils.TokenDecode;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @ClassName : AdminBlogController  //类名
 * @Description :   //描述
 * @Author : YG  //作者
 * @Date: 2020-11-04 13:20  //时间
 */

/**
 * 未测试
 */
@Api(tags ="管理员管理博客模块")
@RestController
public class AdminBlogController {

    @Autowired
    private AdminBlogService adminBlogService;


    @Autowired
    private TokenDecode tokenDecode;
    @ApiOperation(value = "管理员获取全部话题", notes = "管理员获取全部话题")
    @GetMapping("admin/blog/getBlogList/{page}/{size}")
    public Result<PageInfo<BlogGetVO>> getBlogList(@ApiParam(value = "当前页数",name = "page")@PathVariable Integer page,
                                                   @ApiParam(value = "当页大小",name = "size") @PathVariable Integer size)
    {
        PageInfo<GetBlogListVO> blogList = adminBlogService.getBlogList(page, size);
        return new Result(true, StatusCode.OK,"查询成功",blogList);
    }

    @ApiOperation(value = "管理员获取一个话题下全部评论", notes = "管理员获取一个话题下全部评论")
    @GetMapping("admin/blog/getCommentList")
    public Result<PageInfo<GetCommentListVO>> getCommentList(@RequestParam("blogId")@ApiParam(value = "博客id",name = "blogId")Integer blogId,
                                 @ApiParam(value = "当前页数",name = "page")@RequestParam Integer page,
                                 @ApiParam(value = "当页大小",name = "size")@RequestParam Integer size)
    {
        PageInfo<GetCommentListVO> commentList = adminBlogService.getCommentList(blogId, page, size);
        return new Result(true, StatusCode.OK,"查询成功",commentList);
    }

    @ApiOperation(value = "删除一个话题", notes = "删除一个话题")
    @PostMapping("admin/blog/deleteBlog")
    public Result deleteBlog(@RequestParam("blogId")@ApiParam(name = "blogId",value = "博客id")Integer blogId)
    {
        int i = adminBlogService.deleteBlog(blogId);
        return i==1?new Result(true, StatusCode.OK,"删除成功"):new Result(true, StatusCode.ERROR,"删除失败");
    }

    @ApiOperation(value = "删除一个评论", notes = "删除一个评论")
    @PostMapping("admin/blog/deleteComment")
    public Result deleteComment(@RequestParam("commentId")@ApiParam(name = "commentId",value = "评论id") Integer commentId)
    {
        int i=adminBlogService.deleteComment(commentId);
        return i==1?new Result(true, StatusCode.OK,"删除成功"):new Result(true, StatusCode.ERROR,"删除失败");
    }


}
